home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Util / Var / Lex.l < prev    next >
Encoding:
Lex Description  |  1994-12-22  |  3.9 KB  |  146 lines

  1.  
  2. %{
  3. /*
  4.     > FLEX -d -i -I lex.l
  5.     > Dcc lex.yy.c -mD -c
  6. **
  7.     21-08-94 - added FLAG, REFERENCE
  8.     25-09-94 * rewritten
  9.  
  10. */
  11.  
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <stdio.h>
  15. #include <fcntl.h>
  16. #include <ctype.h>
  17. #include "Dyn.h"
  18. #include "node.h"
  19. #include "y.tab.h"
  20. extern FILE *nextfile(void);
  21.  
  22. #define _ESC  "\\"
  23. #define _KET  "%}"
  24. #define _EKET "%]"
  25.  
  26. #define STORE(x) yylval = (int)strdup((x))
  27.  
  28. int  lineno   = 0;
  29. DSTR value    = EmptyDyn;
  30. char linebuffer[1000];
  31.  
  32. /* jeder txt muss mit "" eingesclossen sein!; "\\" werden gestrippt */
  33. char * Strip (const char *txt, int embedded)
  34. {
  35.     char *dest = linebuffer;
  36.     char c = 0;
  37.  
  38.     if (embedded)
  39.     if (*txt == '"')
  40.         ++txt;
  41.  
  42.     while (c = *(txt ++)) {
  43.     if (c == '\\')
  44.         c = *(txt++);
  45.     *(dest++) = c;
  46.     } /* while */
  47.  
  48.     if (embedded)
  49.     if (*(--dest) != '"')
  50.         ++dest;
  51.     *dest = 0;
  52.     return linebuffer;
  53. } /* Strip */
  54.  
  55.  
  56. /* int read(FILE *, char *, int); */
  57. %}
  58.  
  59. ROL  ("%%")
  60. RBRA ("%{")
  61. RKET ("%}")
  62. EBRA ("%[")
  63. EKET ("%]")
  64. ESC  "\\"
  65. SAFECHAR        [^\]\[\t \n%}{;+=\\"/]
  66. LEGALC            [^\]\[\t \n%}{;,+=\\"/]
  67. LEGALS            {LEGALC}+(([\][\n]{LEGALC}*)|([/]{LEGALC}+))*
  68.  
  69. ALNUM           [A-Za-z0-9]
  70. LABEL           [A-Za-z_][A-Za-z_0-9]*
  71.  
  72. STARTLINE       [\n][#]if(def)*[\t ]+{LABEL}
  73. ENDLINE        [\n][#]endif
  74.  
  75.  
  76.  
  77. %start ASSIGN INFRA INTRA INFR2
  78.  
  79. %%
  80.  
  81. [\n]            { ++ lineno; REJECT; }
  82.  
  83. <ASSIGN>PROJECT     {            return PROJECT;   }
  84. <ASSIGN>GLOBAL        {            return GLOBAL;    }
  85. <ASSIGN>CONST        {            return CONST;     }
  86. <ASSIGN>HIDDEN        {            return HIDDEN;    }
  87. <ASSIGN>INTERNAL    {            return INTERNAL;  }
  88. <ASSIGN>GENERIC     {            return GENERIC;   }
  89.  
  90. <ASSIGN>__TYPES     {            return TYPES;   }
  91. <ASSIGN>__NEEDED    {            return NEEDED;  }
  92. <ASSIGN>__DEFAULT   {            return DEFAULT; }
  93. <ASSIGN>{LABEL}     { STORE(yytext); return (NODE_IsType((void*)yylval)) ? GENTYPE : LABEL; }
  94.  
  95. <ASSIGN>[;]        {            return SEMI;  }
  96. <ASSIGN>[,]        {            return KOMMA; }
  97. <ASSIGN>[=]        {            return ASS;   }
  98. <ASSIGN>[+][=]        {            return ADD;   }
  99. <ASSIGN>{RBRA}        {            return RBRA;  }
  100. <ASSIGN>{RKET}        {            return RKET;  }
  101. <ASSIGN>[{]        {            return SBRA;  }
  102. <ASSIGN>[}]        {            return SKET;  }
  103.  
  104. <ASSIGN>{EBRA}        { BEGIN INFRA;  DynClear(&value); return EBRA; }
  105. <ASSIGN>{EKET}        {                      return EKET; }
  106. <INFRA>{ESC}{ESC}   |
  107. <INFRA>{ESC}{EKET}  {            DynCat (&value, yytext + 1); }
  108. <INFRA>{EKET}        { BEGIN ASSIGN; STORE(DynValue(&value)); yyless(0); return VALUE;  }
  109. <INFRA>[\n]        {           yymore(); }
  110. <INFRA>{SAFECHAR}+  |
  111. <INFRA>.        |
  112. <INFRA>[\t ]+        {            DynCat (&value, yytext); }
  113.  
  114. <ASSIGN>[{][{]        { BEGIN INFR2;  DynClear(&value); return SSBRA; }
  115. <ASSIGN>[}][}]        {                      return SSKET; }
  116. <INFR2>{ESC}{ESC}   |
  117. <INFR2>{ESC}[}]     {            DynCat (&value, yytext + 1); }
  118. <INFR2>[}][}]        { BEGIN ASSIGN; STORE(DynValue(&value)); yyless(0); return VALUE;  }
  119. <INFR2>[\n]        {           yymore(); }
  120. <INFR2>{SAFECHAR}+  |
  121. <INFR2>.        |
  122. <INFR2>[\t ]+        {            DynCat (&value, yytext); }
  123.  
  124. <ASSIGN>{ROL}        { BEGIN INTRA;                }
  125. <ASSIGN>["](([^\\"\n]*)([\\]["\\])*)*["] { STORE(Strip(yytext,1)); return VALUE; }
  126. <INTRA>[^\n]*        { BEGIN ASSIGN; STORE(yytext);          return VALUE; }
  127. <ASSIGN>{LEGALS}    {            STORE(Strip(yytext,0)); return VALUE; }
  128.  
  129. {STARTLINE}        { extern char *inittext; if (!strstr(yytext, inittext)) REJECT;
  130.             BEGIN ASSIGN; return BLOCKSTART;  /* Parseblock START */ }
  131. <ASSIGN>{ENDLINE}   {        BEGIN 0;          /* Parseblock END   */ }
  132. [/][/][^\n]*        {                      /* Kommentare       */ }
  133. [ \t]+            {                      /* Whitespace       */ }
  134. [\n]            {                      /* Newlines          */ }
  135. <ASSIGN>.        {                return -1;      /* Unmatched Chars  */ }
  136. <INFRA>.        {                return -1;      /* Unmatched Chars  */ }
  137. <INTRA>.        {                return -1;      /* Unmatched Chars  */ }
  138. .            {                      /* App Source - NOP */ }
  139. <ASSIGN><<EOF>>     { extern char *filename; BEGIN 0; fprintf (stderr, "unexpected EOF in `%s',%d\n",filename, lineno); REJECT; }
  140. <<EOF>>         { BEGIN 0; if ((yyin = nextfile())) { lineno = 0; YY_NEW_FILE; } else return 0; }
  141.  
  142. %%
  143.  
  144.  
  145.  
  146.